var dbConfig = require('../utils/dbconfig');

// 获取orderList
getOrderList = ( req, resp ) => {
    console.log('==获取orderList==')
    console.log(req.query)
    console.log(req.body)
    let { pageNum, pageSize } = req.query
    var sql = "select * from order_info limit ?,? "
    var sqlArr = [pageNum*1-1,pageSize*1]
    dbConfig.sqlConnect(sql,sqlArr,(err,data)=>{
        if (err){
            console.log('获取商品列表失败')
        }else {
            console.log(data)
            resp.send({
                code : 200,
                data : data
            })
        }
    })
}




//封装请求order类
getOrder = (req,res)=>{
    var sql = "select * from test1";
    var sqlArr = [];
    var callBack = (err,data) => {
        if(err){
            console.log('链接出错了~')
        }else{
            res.send({
                'list':data
            })
        }
    }

    dbConfig.sqlConnect(sql,sqlArr,callBack);
}

//携带参数的sql

getOrderById = (req,res)=>{
    //获取请求参数
    console.log(req);
    console.log("============");
    console.log(req.query);
    let {id} = req.query;
    console.log("===========");
    console.log(req.query.id);
    console.log(req.query.pwd);
    var sql = "select * from test1 where id=?";
    var sqlArr = [id];
    console.log("============");
    console.log(sqlArr);
    var callBack = (err,data) => {
        if(err){
            console.log('链接出错了~')
        }else{
            res.send({
                'list':data
            })
        }
    }

    dbConfig.sqlConnect(sql,sqlArr,callBack);
}

module.exports = {
    getOrder,getOrderById,getOrderList
}
